package com.question.view.command.play;

import java.util.List;

import com.question.Design.SingletonMode;
import com.question.entity.Question;
import com.question.entity.User;
import com.question.service.IPlayerService;
import com.question.utils.InputOutUtils;
import com.question.utils.MyUtils;
import com.question.view.Configure;

public class ListCommand extends PlayerSuper {
	
	private IPlayerService playerService= SingletonMode.getPlayerService();
	@Override
	protected void exec(User player) {
		Integer type = QuestionType();
		if(type == null)return;
		Question question = new Question();
		question.setQuestion_state_id(type);
		List<Question> questionList = playerService.questionList(question);
		System.out.printf("%-4s%-30s%s    %10s%20s   %-6s\n","id","问题标题","当前状态","创建时间",Configure.INTEGRAL,"创建人");
		for (Question reQuestion : questionList) {
			System.out.printf("%-4s%-20s%-10s%20s   %3s   %-6s\n",reQuestion.getId(),reQuestion.getQuestion_title(),
							(reQuestion.getQuestion_state_id()==1?Configure.QUESTIONTYPE1:Configure.QUESTIONTYPE2),
							MyUtils.date(reQuestion.getCreate_datetime()),reQuestion.getCredit(),reQuestion.getUser().getDisplay_name());
		}
	}
	private Integer QuestionType() {
		while(true) {
			String [] str = {"*****请输入查看问题类型*****",
					"->all      --查看所有的问题",
					"->solve    --查看解决的问题",
					"->unsolved --未解决的问题"};
			InputOutUtils.print(str);
			String inval = InputOutUtils.inputString("问题类型:", false);
			try {
				return Question.map.get(inval);
			}catch(NullPointerException e) {
				InputOutUtils.print("请输入正确的问题类型");
				if(InputOutUtils.inputString("是否重试[YorN]:", false).equalsIgnoreCase("N"))return null;
			}
		}
	}

}
